<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
${aier_doctype}
<html <s:property value="aier_html_xmlns" escape="false"/>>
<head>
<meta http-equiv="Content-Type" content="${aier_content_type}" />
<meta name="keywords" content="${aier_keyworks}" />
<meta name="description" content="${aier_description}" />
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}ui.css" />
<link href="${aier_css_url}jq/jq.css" rel="Stylesheet" />
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}text.css" />
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}enhanced.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/jq-msg.css" />
<link rel="stylesheet" href="${aier_css_url}proxy/apc.css" />

<script type="text/javascript" src="${aier_js_url}j.js"></script>
<script type="text/javascript" src="${aier_js_url}b.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/hh/ui.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/msg.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/hh/dialog.js"></script>
<script type="text/javascript" src="${aier_js_url}97/WdatePicker.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/cn.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/jq.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/block.js"></script>
<script type="text/javascript" src="${aier_js_url}${aier_jqui_js}custominput.js"></script>
<script type="text/javascript" src="${aier_js_url}${aier_jqui_js}text.js"></script>
<title>分派IC卡</title>

<script type="text/javascript">
$(document).ready(function(){  
	$("#proCardinfo").jqGrid({                
		url:'${aier_url}${aier_urijs}assignprocard_search${aier_suffix}?pid=${pid}',                
		datatype:"json",                
		mtype:'GET',
		
		height:230,  
		colNames:['IC卡编号','派属','使用类型','分派时间 ','到期时间'],                
		colModel:[                    
		{name:'cardnum',index:'cardnum',width:100,align:'center'},                    
		{name:'stateName',index:'stateName',width:100,sortable:false,align:'center'},                    
		{name:'usetype',index:'usetype',width:100, sortable:false,align:'center'},
		{name:'time_str',index:'time_str',width:150,sortable:false,align:'center'},
		{name:'icedate_str',index:'icedate_str',width:150,sortable:false,align:'center'}
		],
		//autowidth:true,
		jsonReader: {
			root:"icCards",
			page: "page",
			total: "page_count",
			records : "count",
			repeatitems: false
		},
		pager: jQuery("#proCardpage"),
		prmNames : {page:"page",sort: "sort"},
		rowNum: 10,
		//rowList: [10, 20, 30],
		sortname: 'cardnum',
		hidegrid: false,
		sortorder: 'asc',
		viewrecords: true,
		caption: 'IC卡信息'
	}).navGrid("#proCardpage", { edit: false, add: false, del: false, search: false });
});
//文本框美化
 $(document).ready(function(){
	    $("input, textarea").addClass("idle");
        $("input, textarea").focus(function(){
                $(this).addClass("activeField").removeClass("idle");
	    }).blur(function(){
                $(this).removeClass("activeField").addClass("idle");
	    });
        });

</script>
</head>
<body>
	<div id="tabs">
		<ul>
			<li><a href="#tabs-1">分派IC卡</a>
			</li>
		</ul>
		<div id="tabs-1" style="height: 500px;">
			<div class="d_content">
				<div>
					<div class="d_scnOut">
						<div class="d_scname">
							<label>分派区域:</label>
						</div>
						<div class="sel_position">
							<select id="area_types" onchange="changearea()">
								<c:forEach var="procity" items="${proCityList }">
									<option value="${procity.cid}">${procity.cname}</option>
								</c:forEach>
							</select>
						</div>
					</div>
					<div class="d_scnOut">
						<div class="d_scname">
							<label>卡前缀:</label>
						</div>
						<div class="sel_position">
							<select id="headadd_types" onchange="changehead()">
								<c:forEach var="head" items="${head_searchList }">
									<option value="${head.ichead}">${head.ichead}</option>
								</c:forEach>
							</select>
						</div>
					</div>

					<div style="margin-left: 250px;margin-top: -80px;">
						<div class="d_scnOut">
							<div class="d_scname">
								<label for="end_txt">分派学校:</label>
							</div>
							<div class="sel_position" id="sel_position_school">
								<select id="school_types">
									<option value="-1">请选择</option>
									<c:forEach var="school" items="${schoolList }">
										<option value="${school.sid}">${school.name}</option>
									</c:forEach>
								</select>
							</div>
						</div>
						<div class="d_scnOut">
							<div class="d_scname">
								<label>卡范围:</label>
							</div>
							<div class="d_ictext">

								<input type="text" id="txt_body_begin" class="txt_scname">
							</div>
							<div class="d_scname"
								style="margin-left: 90px;margin-top: -20px;">
								<label>到</label>
							</div>
							<div class="d_ictext" style="margin-left: 213px;">
								<input type="text" id="txt_body_end" class="txt_scname">

							</div>
						</div>
					</div>

					<div style="margin-top: -40px;margin-left: 650px;">
						<div class="d_scnOut">
							<div class="d_scname">
								<label>该系列当前存量</label>
							</div>
							<div class="d_sctext">
								<span id="txt_head_number">${head_number}</span>

							</div>
						</div>
					</div>

					<button id="b_apcAssign" onclick="assignCard()"
						style="margin-left: 565px;margin-top: -78px;"
						class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
						role="button" aria-disabled="false">
						<span class="ui-button-text">分派</span>
					</button>

				</div>
				
				<div style="margin-top: -25px;margin-left: -325px;">
					<hr width=740 size=1 color=#3F7506
						style="FILTER: alpha(opacity=100,finishopacity=0,style=2)">
				</div>
				<div style="margin-left: 0px;margin-top: 20px">
					<div class="d_scnOut">
						<div class="d_scname">
							<label>派属:</label>
						</div>
						<div class="sel_position">
							<select id="icstate_types">
								<option value="-1">全部</option>
								<option value="10">未分派</option>
								<option value="60">已分派</option>
							</select>
						</div>
					</div>
					<div style="margin-left: 250px;margin-top: -40px;">
						<div class="d_scnOut">
							<div class="d_scname">
								<label>批次:</label>
							</div>
							<div class="sel_position">
								<select id="head_types">
									<option value="-1">请选择</option>
									<c:forEach var="head" items="${head_searchList }">
										<option value="${head.ichead}">${head.ichead}</option>
									</c:forEach>
								</select>
							</div>
						</div>
					</div>
					<button id="b_apcSearch" onclick="search()"
						style="margin-left: 565px;margin-top: -80px;"
						class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
						role="button" aria-disabled="false">
						<span class="ui-button-text">查询</span>
					</button>

				</div>

				<div style="margin-top: 0px;margin-left: 50px;">
					<table id="proCardinfo"></table>
					<div id="proCardpage"></div>
				</div>
				
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
	$("#tabs").tabs();
	//更换区域
	function changearea(){
		var pid = "${pid}";
		var area_id = $('#area_types  option:selected').val(); 
		var fun = function(data){
			var t = "<select id='school_types'><option value='-1'>请选择</option>";
			if(data.schoolList!=null&&data.schoolList.length>0){
				for ( var i = 0; i < data.schoolList.length; i++) {
					var school = data.schoolList[i];
					t += "<option value="+school.sid+">" + school.name + "</option>";
				}
			};
			t += "</select>";
			$('#sel_position_school').html(t);
		};
		exeAjax(ajaxUrl("${aier_url}${aier_urijs}assignprocard_changearea${aier_suffix}"), fun, 
			{"pid" :pid,"area_id" : area_id});		
	}
	//更换卡前缀
	function changehead(){
		var pid = "${pid}";
		var ic_head_add = $('#headadd_types  option:selected').val();
		var fun = function(data){
			$('#txt_head_number').html(data.head_number);
		};
		exeAjax(ajaxUrl("${aier_url}${aier_urijs}assignprocard_changehead${aier_suffix}"), fun, 
			{"pid" :pid,"ic_head_add" : ic_head_add});	
	}
	//查询
	function search(){
		var pid = "${pid}";
		var ic_state = $('#icstate_types  option:selected').val();
		var ic_head = $('#head_types  option:selected').val();
		jQuery("#proCardinfo").jqGrid('setGridParam',{url:"${aier_url}${aier_urijs}assignprocard_search${aier_suffix}?pid="+pid
			+"&ic_state="+ic_state+"&ic_head="+ic_head,page:1}).trigger("reloadGrid");
	}
	
	//分派
	function assignCard(){
		var pid = "${pid}";
		var area_id = $('#area_types  option:selected').val(); 
		var school_id = $('#school_types  option:selected').val();
		var ic_head_add = $('#headadd_types  option:selected').val();
		var body_begin = $('#txt_body_begin').val();
		var body_end = $('#txt_body_end').val();
		if(school_id==-1){
			$().message("请选择一个学校");
			return
		}
		if(body_begin==""||body_end==""){
			$().message("请输入卡范围");
			return
		}
		if(body_begin>body_end){
			$().message("卡范围必须从小到大");
			return
		}
		if(body_begin.length!=6||body_end.length!=6){
			$().message("请输入6位数的卡范围");
			return	
		}
		/**if(ic_head_add==-1){
			$().message("请选择一个卡前缀");
			return
		}*/		
		var fun = function(data){
			if(data.s==1){
				alert("分派卡成功，共分派了"+(body_end-body_begin+1)+"张卡");
				changehead();
				search();
			}else{
				alert("分派卡失败:卡"+data.ic.ichead+data.ic.icbody+"已经分派");
			}
		};
		exeAjax(ajaxUrl("${aier_url}${aier_urijs}assignprocard_assignCard${aier_suffix}"), fun, 
			{"pid" :pid,"area_id" : area_id,"school_id":school_id,"ic_head_add":ic_head_add,"body_begin":body_begin,"body_end":body_end});
	}

</script>
</html>